#include <iostream>

using namespace std;

int main()
{
    string s, s1 = "", s2 = "";
    int k, i=0;
    cout << "Введите скобочную последовательность: ";
    getline(cin, s);
    for (int i =0; i<s.size(); i++)
    {
        if (s[i] == '(' or s[i] == '[' or s[i] == '{' or s[i] == '<' or s[i] == ')' or s[i] == ']' or s[i] == '}' or s[i] == '>')
        {
            s1 = s1 + s[i];
        }
    }
    for (i = 0; i < s1.size(); i++)
    {
        if (s1[i] == '(' or s1[i] == '[' or s1[i] == '{' or s1[i] == '<')
        {
            s2 = s2 + s1[i];
        }
        else if (s1[i] == ')' and s2.size() > 0 and s2[s2.size() - 1] == '(')
        {
            s2 = s2.substr(0, s2.size()-1);
        }
        else if (s[i] == ']' and s2.size() > 0 and s2[s2.size() - 1] == '[')
        {
            s2 = s2.substr(0, s2.size()-1);
        }
        else if (s1[i] == '}' and s2.size() > 0 and s2[s2.size() - 1] == '{')
        {
            s2 = s2.substr(0, s2.size()-1);
        }
        else if (s1[i] == '>' and s2.size() > 0 and s2[s2.size() - 1] == '<')
        {
            s2 = s2.substr(0, s2.size()-1);
        }
        else
        {
            k = k + 1;
        }
    }
    if (s2 == "" and k == 0)
    {
        cout << "True" << endl;
    }
    else
    {
        cout << "False" << endl;
    }
}
